<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="en">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="https://fonts.loli.net/css?family=Lato:300,300italic,400,400italic,700,700italic|Lobster:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico?v=5.1.4">


  <link rel="mask-icon" href="/images/favicon.ico?v=5.1.4" color="#222">


  <link rel="manifest" href="/images/manifest.json">




  <meta name="keywords" content="machine learning,Bayesian Optimizer,hyperparameter tuning,automl," />










<meta name="description" content="优化器是机器学习中很重要的一个环节。当确定损失函数时，你需要一个优化器使损失函数的参数能够快速有效求解成功。优化器很大程度影响计算效率。越来越多的超参数调整是通过自动化方式完成，使用明智的搜索在更短的时间内找到最佳超参组合，无需在初始设置之外进行手动操作。">
<meta name="keywords" content="machine learning,Bayesian Optimizer,hyperparameter tuning,automl">
<meta property="og:type" content="article">
<meta property="og:title" content="Auto Machine Learning笔记 - Bayesian Optimization">
<meta property="og:url" content="http://codewithzhangyi.com/2018/07/31/Auto Hyperparameter Tuning - Bayesian Optimization/index.html">
<meta property="og:site_name" content="Zhang Yi">
<meta property="og:description" content="优化器是机器学习中很重要的一个环节。当确定损失函数时，你需要一个优化器使损失函数的参数能够快速有效求解成功。优化器很大程度影响计算效率。越来越多的超参数调整是通过自动化方式完成，使用明智的搜索在更短的时间内找到最佳超参组合，无需在初始设置之外进行手动操作。">
<meta property="og:locale" content="en">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/001.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/010.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/013.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/010.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/003.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/004.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/005.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/006.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/007.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/008.png?raw=true">
<meta property="og:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/013.jpeg?raw=true">
<meta property="og:updated_time" content="2019-02-11T07:45:32.841Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Auto Machine Learning笔记 - Bayesian Optimization">
<meta name="twitter:description" content="优化器是机器学习中很重要的一个环节。当确定损失函数时，你需要一个优化器使损失函数的参数能够快速有效求解成功。优化器很大程度影响计算效率。越来越多的超参数调整是通过自动化方式完成，使用明智的搜索在更短的时间内找到最佳超参组合，无需在初始设置之外进行手动操作。">
<meta name="twitter:image" content="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/001.png?raw=true">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://codewithzhangyi.com/2018/07/31/Auto Hyperparameter Tuning - Bayesian Optimization/"/>






<script data-ad-client="ca-pub-2691877571661707" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  <title>Auto Machine Learning笔记 - Bayesian Optimization | Zhang Yi</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Zhang Yi</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle" style="color:#fff">
    <button>MENU</button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-projects">
          <a href="/projects/" rel="section">
            
            Projects
          </a>
        </li>
      
        
        <li class="menu-item menu-item-blog">
          <a href="/blog/" rel="section">
            
            Blog
          </a>
        </li>
      
        
        <li class="menu-item menu-item-activity">
          <a href="/activity/" rel="section">
            
            Activity
          </a>
        </li>
      
        
        <li class="menu-item menu-item-list-100">
          <a href="/list-100/" rel="section">
            
            List 100
          </a>
        </li>
      
        
        <li class="menu-item menu-item-friends">
          <a href="/friends/" rel="section">
            
            Friends
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
            Search
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="Searching..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>


 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://codewithzhangyi.com/2018/07/31/Auto Hyperparameter Tuning - Bayesian Optimization/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="ZhangYi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Zhang Yi">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Auto Machine Learning笔记 - Bayesian Optimization</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-07-31T18:20:14+08:00">
                2018-07-31
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/07/31/Auto Hyperparameter Tuning - Bayesian Optimization/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/07/31/Auto Hyperparameter Tuning - Bayesian Optimization/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>visitors
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>优化器是机器学习中很重要的一个环节。当确定损失函数时，你需要一个优化器使损失函数的参数能够快速有效求解成功。优化器很大程度影响计算效率。越来越多的超参数调整是通过自动化方式完成，使用明智的搜索在更短的时间内找到最佳超参组合，无需在初始设置之外进行手动操作。<br><a id="more"></a><br><strong>贝叶斯优化</strong>（Bayesian Optimization）是基于模型的超参数优化，已应用于机器学习超参数调整，结果表明该方法可以在测试集上实现更好的性能，同时比随机搜索需要更少的迭代。此外，现在有许多Python库可以为任何机器学习模型简化实现贝叶斯超参数调整。<br><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/001.png?raw=true" width="70%/"></p>
<h2 id="1-超参数是什么？"><a href="#1-超参数是什么？" class="headerlink" title="1. 超参数是什么？"></a>1. 超参数是什么？</h2><ul>
<li>在模型开始学习过程之前人为设置值的参数，而不是（像bias、weights）通过训练可得到的参数数据。</li>
<li>这些参数定义关于模型更高层次的概念（模型复杂性、学习能力等）。</li>
<li>比如说随机梯度下降算法中的学习速率/learning rate，出于计算复杂度和算法效率等，我们并不能从数据中直接学习一个比较不错的学习速度。但学习速率却又是十分重要的，较大的学习速率不易令模型收敛到较合适的较小值解，而较小的学习速率却又常常令模型的训练速度大大降低。对于像学习速率这样的超参数，我们通常需要在训练模型之前设定。因此，对于超参数众多的复杂模型，调超参技能显得很重要。</li>
</ul>
<h2 id="2-常用的调超参方法有哪些？"><a href="#2-常用的调超参方法有哪些？" class="headerlink" title="2. 常用的调超参方法有哪些？"></a>2. 常用的调超参方法有哪些？</h2><ol>
<li><strong>Grid Search</strong> 网格搜索/穷举搜索<ul>
<li>搜索整个超参数空间，在高维空间容易遇到维度灾难，不实用。</li>
<li>网格搜索是一种昂贵的方法。假设我们有n个超参数，每个超参数有两个值，那么配置总数就是2的N次方。因此，仅在少量配置上进行网格搜索是可行的。</li>
<li>网格搜索可以并行化，使得网格搜索在足够的计算能力下更加可行。</li>
<li>每次trial之间是相互独立的，不能利用先验知识选择下一组超参数。</li>
</ul>
</li>
<li><strong>Random Search</strong> 随机搜索<ul>
<li>稀疏的简单抽样，试验之间是相互独立的，不能利用先验知识选择下一组超参数。</li>
<li>超参通过并行选择，但试验次数要少得多，而性能却相当。一些超参可能会产生良好的性能，另一些不会。</li>
</ul>
</li>
<li><strong>Heuristic Tuning</strong> 手动调参<ul>
<li>经验法，耗时长。</li>
</ul>
</li>
<li><strong>Automatic Hyperparameter Tuning</strong> 自动超参数调优<ul>
<li>自动超参数调整形成了关于超参数设置和模型性能之间关系的知识，能利用先验知识选择下一组超参数。</li>
<li>首先在多个配置中收集性能，然后进行一些推断并确定接下来要尝试的配置。目的是在找到最佳状态时尽量减少试验次数。</li>
<li>这个过程本质上是顺序的，不容易并行化。</li>
<li>调整超参数的大多数方法都属于基于顺序模型的全局优化（SMBO）。这些方法使用代理函数来逼近真正的黑盒函数。SMBO的内部循环是对该替代品的优化，或者对代理进行某种转换。最大化此代理的配置将是下一个应该尝试的配置。SMBO算法在优化替代品的标准以及他们根据观察历史对替代品进行建模的方式上有所不同。最近在文献中提出了几种用于超参数的SMBO方法：<ul>
<li><strong>Bayesian Optimization</strong><br>使用<em>高斯过程</em>对代理进行建模，通常优化 Expected Improvement(EI)，这是新试验将在当前最佳观察上改进的预期概率。高斯过程是函数的分布。来自高斯过程的样本是整个函数。训练高斯过程涉及将此分布拟合到给定数据，以便生成接近观察数据的函数。使用高斯过程，可以计算搜索空间中任何点的EI。接下来将尝试给出最高的EI。贝叶斯优化通常为连续超参数（例如learning rate, regularization coefficient…）提供 non-trivial/off-the-grid 值，并且在一些好的数据集上击败人类表现。Spearmint是一个众所周知的贝叶斯优化实现。</li>
<li><strong>SMAC</strong><br>使用<em>随机森林</em>对目标函数进行建模，从随机森林认为最优的区域（高EI）中抽取下一个点。</li>
<li><strong>TPE</strong><br>是SMAC的改进版本，其中两个分离的模型用于模拟后验。众所周知的TPE实现是hyperopt。</li>
</ul>
</li>
</ul>
</li>
</ol>
<h2 id="3-概念解释"><a href="#3-概念解释" class="headerlink" title="3. 概念解释"></a>3. 概念解释</h2><ul>
<li>高斯过程<br><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/010.png?raw=true" width="70%/"><br>上图里那么多线就是高斯过程的体现。<br>要使用贝叶斯优化，需要一种能灵活地在目标函数上建立分布的方法。这比在实数上建立分布更棘手，因为我们需要一个这样的分布来表示我们对每个x的f(x)的信念。如果x包含连续的超参数，那么我们必须为f(x)建模无限多的x，即构造它的分布。对于这个问题，<strong>高斯过程</strong>是一种优雅的方法。实际上，高斯过程生成多维高斯分布，并且存在足够灵活以模拟任何目标函数的模样。<br><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/013.png?raw=true" alt=""></li>
<li>Prior Function 先验函数<br>基于概率分布，用于描述目标函数的分布，拟合目标函数曲线。不同的分布，PF不同，效果是不一样的。</li>
<li>Acquisition Function 收获函数 = max(mean + var)<br>用于从候选集中选择一个新的点。贝叶斯优化的效果与AF的设计有较大的关系，由于此类function可能陷入局部最优解，因此在选点时，需考虑不能过早进入局部最优。AF计算EI，用来选择下一个采样点。<ul>
<li>mean均值大：<br>多去采样这些点会帮助我们更好的了解这个函数形态。</li>
<li>var方差大：<br>表示我们对该点的了解甚少。</li>
</ul>
</li>
<li>采样点<br>每一个采样点就是原理解析里的黑点。每个采样点是基于前面n个点的多变量高斯分布的假设以及最大化AF而得到的，现目前为止认为的y的最大值最可能出现的位置。<ul>
<li>一开始，采样数据少，算法会采标准差大的点。采样一定数目后，标准差的值会下降很多，此时采样点的选择就更多的受到均值的影响，采样点就更大概率的出现在真正最大值附近。</li>
</ul>
</li>
</ul>
<h2 id="4-Bayesian-Optimizer-原理解析"><a href="#4-Bayesian-Optimizer-原理解析" class="headerlink" title="4. Bayesian Optimizer 原理解析"></a>4. Bayesian Optimizer 原理解析</h2><p>贝叶斯优化基于高斯过程。<br><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/010.png?raw=true" width="70%/"><br><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/003.png?raw=true" width="70%/"></p>
<ul>
<li>上图2个evaluations黑点，是两次评估后显示替代模型的初始值估计，会影响下一个点的选择，穿过这两个点的曲线可以画出非常多条，如上上图</li>
<li>红色虚线曲线是实际真正的目标函数</li>
<li>黑色实线曲线是代理模型的目标函数的均值</li>
<li>灰色区域是代理模型的目标函数的方差</li>
<li>只有两个点，拟合的效果稍差，根据下方的紫色的EI曲线，最左侧的最大值EI为下一个点</li>
</ul>
<p><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/004.png?raw=true" width="70%/"></p>
<ul>
<li>3个evaluations黑点</li>
<li>灰色区域是代理模型的目标函数的方差，黑点越多，灰色区域面积越小，误差越小</li>
<li>根据下方的紫色的EI曲线，左侧的最大值EI为第四个拟合点</li>
</ul>
<p><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/005.png?raw=true" width="70%/"></p>
<ul>
<li>4个evaluations黑点</li>
<li>黑点越多，灰色区域面积越小，误差越小，代理模型越接近真实模型的目标函数</li>
<li>根据下方的紫色的EI曲线，最大值EI为第五个拟合点，同理类推…</li>
</ul>
<p><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/006.png?raw=true" width="70%/"><br><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/007.png?raw=true" width="70%/"><br><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/008.png?raw=true" width="70%/"></p>
<ul>
<li>8个黑点</li>
<li>黑色代理曲线已经十分接近红色真实目标函数，灰色区域也越来越小，拟合效果不错。</li>
</ul>
<h2 id="5-Bayesian-Optimizer-基本思想"><a href="#5-Bayesian-Optimizer-基本思想" class="headerlink" title="5. Bayesian Optimizer 基本思想"></a>5. Bayesian Optimizer 基本思想</h2><p>一句话总结：建立目标函数的概率模型，并用它来选择最有希望的超参数来评估真实的目标函数。<br>基本思想是：利用先验知识逼近未知目标函数的后验分布从而调节超参。花一点时间选择下一个超参数，以减少对目标函数的调用。</p>
<ol>
<li>建立代理模型的目标函数（Prior Function/先验函数）</li>
<li>找到在代理上表现最佳的超参数（利用EI值，根据Acquisition Function得出EI）</li>
<li>将这些超参数应用于真正的目标函数</li>
<li>更新包含新结果的代理模型</li>
<li>重复步骤2-4，直到达到最大迭代次数或时间</li>
</ol>
<p>基于顺序模型的优化方法（SMBO）是贝叶斯优化的形式化。顺序是指一个接一个地运行试验，每次通过应用贝叶斯推理和更新概率模型（代理）来尝试更好的超参数。</p>
<h2 id="6-Bayesian-Optimizer-在python中的包"><a href="#6-Bayesian-Optimizer-在python中的包" class="headerlink" title="6. Bayesian Optimizer 在python中的包"></a>6. Bayesian Optimizer 在python中的包</h2><p>Python中有几个贝叶斯优化库，它们在目标函数的代理算法上有所不同。</p>
<ul>
<li>Spearmint（高斯过程代理）</li>
<li>SMAC（随机森林回归）</li>
<li>Hyperopt（Tree Parzen Estimator-TPE）</li>
</ul>
<h2 id="7-Bayesian-Optimizer-优点"><a href="#7-Bayesian-Optimizer-优点" class="headerlink" title="7. Bayesian Optimizer 优点"></a>7. Bayesian Optimizer 优点</h2><ul>
<li>能利用先验知识高效地调节超参数，每个试验不独立，前一个推动下一个选择</li>
<li>通过减少计算任务而加速寻找最优参数的进程</li>
<li>不依赖人为猜测所需的样本量为多少，优化技术基于随机性，概率分布</li>
<li>在目标函数未知且计算复杂度高的情况下极其强大</li>
<li>通常适用于连续值的超参，例如 learning rate, regularization coefficient</li>
<li>在测试集表现优秀于手工调参结果，泛化性/鲁棒性好</li>
<li>不易陷入局部最优：<br>  EI的计算根据 Acquisition Function收获函数计算所得：<ul>
<li><strong>探索</strong>和<strong>开发</strong>是解释现象和优化算法的常用术语。</li>
<li>对于贝叶斯优化，一旦找到局部最优解，会在这个区域不断采样，很容易陷入局部最优。为了减轻这个，贝叶斯优化会使用“ 收获函数Acquisition Function ” 来平衡“探索”和“开发”，下一个点的选择要在这两者之间存在权衡。</li>
<li>下一个选择点（x）应该具有高均值（开发）和高方差（探索）。<br><img src="https://github.com/YZHANG1270/Markdown_pic/blob/master/2018/07/bayesian%20optimizer/013.jpeg?raw=true" alt=""></li>
</ul>
</li>
</ul>
<h2 id="8-其他优秀文章与论文链接🔗"><a href="#8-其他优秀文章与论文链接🔗" class="headerlink" title="8. 其他优秀文章与论文链接🔗"></a>8. 其他优秀文章与论文链接🔗</h2><ul>
<li><a href="https://zhuanlan.zhihu.com/p/29779000" target="_blank" rel="noopener">贝叶斯优化: 一种更好的超参数调优方式</a></li>
<li><a href="https://www.iro.umontreal.ca/~bengioy/cifar/NCAP2014-summerschool/slides/Ryan_adams_140814_bayesopt_ncap.pdf" target="_blank" rel="noopener">哈佛教材：A Tutorial on Bayesian Optimization for Machine Learning</a></li>
<li><a href="https://towardsdatascience.com/shallow-understanding-on-bayesian-optimization-324b6c1f7083" target="_blank" rel="noopener">Shallow Understanding on Bayesian Optimization</a></li>
<li><a href="https://cloud.google.com/blog/products/gcp/hyperparameter-tuning-cloud-machine-learning-engine-using-bayesian-optimization" target="_blank" rel="noopener">谷歌cloudml也在用贝叶斯优化</a></li>
<li><a href="https://arxiv.org/pdf/1012.2599.pdf" target="_blank" rel="noopener">A Tutorial on Bayesian Optimization of Expensive Cost Functions, with Application to Active User Modeling and Hierarchical Reinforcement Learning</a></li>
<li><a href="http://papers.nips.cc/paper/4522-practical-bayesian-optimization-of-machine-learning-algorithms.pdf" target="_blank" rel="noopener">Practical Bayesian Optimization of Machine Learning Algorithms</a></li>
<li><a href="https://towardsdatascience.com/automated-machine-learning-hyperparameter-tuning-in-python-dfda59b72f8a" target="_blank" rel="noopener">Automated Machine Learning Hyperparameter Tuning in Python</a></li>
<li><a href="https://towardsdatascience.com/a-conceptual-explanation-of-bayesian-model-based-hyperparameter-optimization-for-machine-learning-b8172278050f" target="_blank" rel="noopener">A Conceptual Explanation of Bayesian Hyperparameter Optimization for Machine Learning</a></li>
<li><a href="http://gpss.cc/gpmc17/slides/LancasterMasterclass_1.pdf" target="_blank" rel="noopener">Introduction to Bayesian Optimization</a></li>
</ul>
<p>写的不一定全对，如果有说错的地方，欢迎指正。</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>打赏2块钱，帮我买杯咖啡，继续创作，谢谢大家！☕~</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechat.png" alt="ZhangYi WeChat Pay"/>
        <p>WeChat Pay</p>
      </div>
    

    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/machine-learning/" rel="tag"># machine learning</a>
          
            <a href="/tags/Bayesian-Optimizer/" rel="tag"># Bayesian Optimizer</a>
          
            <a href="/tags/hyperparameter-tuning/" rel="tag"># hyperparameter tuning</a>
          
            <a href="/tags/automl/" rel="tag"># automl</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/07/26/AutoML/" rel="next" title="Auto Machine Learning笔记 - Auto-Sklearn">
                <i class="fa fa-chevron-left"></i> Auto Machine Learning笔记 - Auto-Sklearn
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/08/07/Machine Learning笔记 - Pipelines 制作教程/" rel="prev" title="Auto Machine Learning笔记 - Pipelines 制作教程">
                Auto Machine Learning笔记 - Pipelines 制作教程 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-2691877571661707"
     data-ad-slot="1301633292"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="ZhangYi" />
            
              <p class="site-author-name" itemprop="name">ZhangYi</p>
              <p class="site-description motion-element" itemprop="description">花时间做那些别人看不见的事~！</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">42</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">categories</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">80</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/YZHANG1270" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i></a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:YZHANG1270@gmail.com" target="_blank" title="邮箱">
                      
                        <i class="fa fa-fw fa-envelope"></i></a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/p/1005053340707810?is_all=1" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-weibo"></i></a>
                  </span>
                
            </div>
          

          
          

          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-超参数是什么？"><span class="nav-text">1. 超参数是什么？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-常用的调超参方法有哪些？"><span class="nav-text">2. 常用的调超参方法有哪些？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-概念解释"><span class="nav-text">3. 概念解释</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-Bayesian-Optimizer-原理解析"><span class="nav-text">4. Bayesian Optimizer 原理解析</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-Bayesian-Optimizer-基本思想"><span class="nav-text">5. Bayesian Optimizer 基本思想</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-Bayesian-Optimizer-在python中的包"><span class="nav-text">6. Bayesian Optimizer 在python中的包</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-Bayesian-Optimizer-优点"><span class="nav-text">7. Bayesian Optimizer 优点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-其他优秀文章与论文链接🔗"><span class="nav-text">8. 其他优秀文章与论文链接🔗</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">ZhangYi</span>

  
</div>








  <div class="footer-custom">All content under <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/">CC BY-NC-ND 4.0</a></div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      visitors
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>


  


  
  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  

    
      <script id="dsq-count-scr" src="https://codewithzhangyi.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'http://codewithzhangyi.com/2018/07/31/Auto Hyperparameter Tuning - Bayesian Optimization/';
          this.page.identifier = '2018/07/31/Auto Hyperparameter Tuning - Bayesian Optimization/';
          this.page.title = 'Auto Machine Learning笔记 - Bayesian Optimization';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://codewithzhangyi.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  
  


  

  

</body>
</html>
